import { GET_INIT_LIST, INPUT_VALUE_CHANGE, PUSH_ARR_DATA } from './actionTypes'
import axios from 'axios';

export const getInitialListItemAction = (data) => ({
  type: GET_INIT_LIST,
  value: data
})
export const inputValueChangeAction = (data) => ({
  type: INPUT_VALUE_CHANGE,
  value: data
})
export const pushArrDataAction = (data) => ({
  type: PUSH_ARR_DATA,
  value: data
})

export const getListItem = () => {
  return (dispatch) => {
    axios.get('https://www.easy-mock.com/mock/5c4685c11172f17a5159ac57/list').then((res)=>{
      const action = getInitialListItemAction(res.data)
      dispatch(action)
    }).catch((err)=> {
      console.log(err)
    })
  }
}

export const inputValueChange = (value) => {
  return (dispatch) => {
    const action = inputValueChangeAction(value)
    dispatch(action)
  }
}
export const pushArrData = (value) => {
  return (dispatch) => {
    const action = pushArrDataAction(value)
    dispatch(action)
  }
}